{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "In C:\\Users\\Han\\.conda\\envs\\my_project1\\lib\\site-packages\\matplotlib\\mpl-data\\stylelib\\_classic_test.mplstyle: \n",
      "The text.latex.preview rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
      "In C:\\Users\\Han\\.conda\\envs\\my_project1\\lib\\site-packages\\matplotlib\\mpl-data\\stylelib\\_classic_test.mplstyle: \n",
      "The mathtext.fallback_to_cm rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
      "In C:\\Users\\Han\\.conda\\envs\\my_project1\\lib\\site-packages\\matplotlib\\mpl-data\\stylelib\\_classic_test.mplstyle: Support for setting the 'mathtext.fallback_to_cm' rcParam is deprecated since 3.3 and will be removed two minor releases later; use 'mathtext.fallback : 'cm' instead.\n",
      "In C:\\Users\\Han\\.conda\\envs\\my_project1\\lib\\site-packages\\matplotlib\\mpl-data\\stylelib\\_classic_test.mplstyle: \n",
      "The validate_bool_maybe_none function was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
      "In C:\\Users\\Han\\.conda\\envs\\my_project1\\lib\\site-packages\\matplotlib\\mpl-data\\stylelib\\_classic_test.mplstyle: \n",
      "The savefig.jpeg_quality rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
      "In C:\\Users\\Han\\.conda\\envs\\my_project1\\lib\\site-packages\\matplotlib\\mpl-data\\stylelib\\_classic_test.mplstyle: \n",
      "The keymap.all_axes rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
      "In C:\\Users\\Han\\.conda\\envs\\my_project1\\lib\\site-packages\\matplotlib\\mpl-data\\stylelib\\_classic_test.mplstyle: \n",
      "The animation.avconv_path rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
      "In C:\\Users\\Han\\.conda\\envs\\my_project1\\lib\\site-packages\\matplotlib\\mpl-data\\stylelib\\_classic_test.mplstyle: \n",
      "The animation.avconv_args rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n"
     ]
    }
   ],
   "source": [
    "import networkx as nx\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import math as math\n",
    "import time \n",
    "import os\n",
    "from sklearn.feature_extraction.text import TfidfVectorizer\n",
    "from sklearn.metrics.pairwise import linear_kernel\n",
    "import matplotlib.font_manager as fm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.rc(\"font\", family = 'Malgun Gothic')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_excel(r\".xlsx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Label</th>\n",
       "      <th>id</th>\n",
       "      <th>Sex</th>\n",
       "      <th>Party</th>\n",
       "      <th>Year</th>\n",
       "      <th>Undergraduate_school</th>\n",
       "      <th>Final_degree</th>\n",
       "      <th>Job</th>\n",
       "      <th>Home</th>\n",
       "      <th>K_means</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>용혜인</td>\n",
       "      <td>Female</td>\n",
       "      <td>Basic Income Party</td>\n",
       "      <td>1990s</td>\n",
       "      <td>경희대학교</td>\n",
       "      <td>B.A.</td>\n",
       "      <td>사회운동</td>\n",
       "      <td>Ownership</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>강득구</td>\n",
       "      <td>Male</td>\n",
       "      <td>Democratic Party</td>\n",
       "      <td>1960s</td>\n",
       "      <td>성균관대학교</td>\n",
       "      <td>M.A.</td>\n",
       "      <td>정당인</td>\n",
       "      <td>Ownership</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Label   id     Sex               Party   Year Undergraduate_school  \\\n",
       "0      1  용혜인  Female  Basic Income Party  1990s                경희대학교   \n",
       "1      2  강득구    Male    Democratic Party  1960s               성균관대학교   \n",
       "\n",
       "  Final_degree   Job       Home  K_means  \n",
       "0         B.A.  사회운동  Ownership        4  \n",
       "1         M.A.   정당인  Ownership        1  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head(2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Figure 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_school(school):\n",
    "    par = ''\n",
    "    if school == '창원대학교' : par = 'Changwon National University'\n",
    "    if school == '경북대학교' : par = 'Kyungpook National University'\n",
    "    if school == '성균관대학교' : par = 'Sungkyunkwan University'\n",
    "    if school == '경남대학교' : par = 'Kyungnam University'\n",
    "    if school == '서울대학교' : par = 'Seoul National University'\n",
    "    if school == '이화여자대학교' : par = 'Ewha Womans University'\n",
    "    if school == '전남대학교' : par = 'Chonnam National University'\n",
    "    if school == '충남대학교' : par = 'Chungnam National University'\n",
    "    if school == '건국대학교' : par = 'Konkuk University'\n",
    "    if school == '경희대학교' : par = 'Kyung Hee University'\n",
    "    if school == '고려대학교' : par = 'Korea University'\n",
    "    if school == '동국대학교' : par = 'Dongguk University'\n",
    "    if school == '울산대학교' : par = 'University of Ulsan'\n",
    "    if school == '중앙대학교' : par = 'Chung-Ang University'\n",
    "    if school == '한국외국어대학교' : par = 'Hankuk University of Foreign Studies'\n",
    "    if school == '인천대학교' : par = 'Incheon National University'\n",
    "    if school == '동아대학교' : par = 'Dong-A University'\n",
    "    if school == '광주대학교' : par = 'Gwangju University'\n",
    "    if school == '한양대학교' : par = 'Hanyang University'\n",
    "    if school == '사관학교' : par = 'Korea Military Academy'\n",
    "    if school == '영남대학교' : par = 'Yeungnam University'\n",
    "    if school == '한국방송통신대학교' : par = 'Korea National Open University'\n",
    "    if school == '연세대학교' : par = 'Yonsei University'\n",
    "    if school == '북경대학교' : par = 'Peking University'\n",
    "    if school == '숙명여자대학교' : par = \"Sookmyung Women's University\"\n",
    "    if school == '전북대학교' : par = 'Chonbuk National University'\n",
    "    if school == '부산대학교' : par = 'Pusan National University'\n",
    "    if school == '원광대학교' : par = 'Wonkwang University'\n",
    "    if school == '한밭대학교' : par = 'Hanbat National University'\n",
    "    if school == '세종대학교' : par = 'Sejong University'\n",
    "    if school == ' 관동대학교' : par = 'Kwandong University'\n",
    "    if school == '충북대학교' : par = 'Chungbuk National University'\n",
    "    if school == '성결대학교' : par = 'Sungkyul University'\n",
    "    if school == '한국항공대학교' : par = 'Korea Aerospace University'\n",
    "    if school == '서울산업대학교' : par = 'Seoul National University of Science and Technology'\n",
    "    if school == '부산외국어대학교' : par = 'Busan University of Foreign Studies'\n",
    "    if school == '인하대학교' : par = 'Inha University'\n",
    "    if school == '경성대학교' : par = 'Kyungsung University'\n",
    "    if school == '서강대학교' : par = 'Sogang University'\n",
    "    if school == '조선대학교' : par = 'Chosun University'\n",
    "    if school == '가톨릭관동대학교' : par = 'Catholic Kwandong University'\n",
    "    if school == '숭실대학교' : par = 'Soongsil University'\n",
    "    if school == '고려사이버대학교' : par = 'Korea Cyber University'\n",
    "    if school == '순천향대학교' : par = 'Soonchunhyang University'\n",
    "    if school == '서울시립대학교' : par = 'University of Seoul'\n",
    "    if school == '제주대학교' : par = 'Jeju National University'\n",
    "    if school == '상명대학교' : par = 'Sangmyung University'\n",
    "    if school == '국민대학교' : par = 'Kookmin University'\n",
    "    if school == '한신대학교' : par = 'Hanshin University'\n",
    "    if school == '경찰대학교' : par = 'Korean National Police University'\n",
    "    if school == '중동고등학교' : par = 'ungdong High School'\n",
    "    if school == '울산과학대학교' : par = 'Ulsan College'\n",
    "    if school == '삼육간호전문대학교' : par = 'Sahmyook Health University College'\n",
    "    if school == '광운대학교' : par = 'Kwangwoon University'\n",
    "    if school == '초당대학교' : par = 'Chodang University'\n",
    "    if school == '한국체육대학교' : par = 'Korea National Sport University'\n",
    "    if school == '경기대학교' : par = 'Kyonggi University'\n",
    "    if school == '가천대학교' : par = 'Gachon University'\n",
    "    if school == '한국애니메이션고등학교' : par = 'Korean Animation High School'\n",
    "    if school == '대명정보대학교' : par = 'Daemyung University'\n",
    "    if school == '대구대학교' : par = 'Daegu University'\n",
    "    if school == '청주대학교' : par = 'Cheongju University'\n",
    "    if school == '단국대학교' : par = 'Dankook University'\n",
    "    if school == '양서종합고등학교' : par = 'Yangseo General High School'\n",
    "    if school == '계명대학교' : par = 'Keimyung University'\n",
    "    if school == '경원대학교' : par = 'Kyungwon University'\n",
    "    if school == '신라대학교' : par = 'Silla University'\n",
    "    if school == '북경외국어대학교' : par = 'Beijing Foreign Studies University'\n",
    "     \n",
    "    \n",
    "    \n",
    "    return par\n",
    "\n",
    "    \n",
    "df['Undergraduate_school'] = df['Undergraduate_school'].apply(lambda x:get_school(x)) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_job(job):\n",
    "    par = ''\n",
    "    if job == '기업인' : par = 'Business'\n",
    "    if job == '정당인' : par = 'Party'\n",
    "    if job == '학계' : par = 'Academia'\n",
    "    if job == '공무원' : par = 'Public'\n",
    "    if job == '보좌관' : par = 'Secretary'\n",
    "    if job == '사회운동' : par = 'Social movement'\n",
    "    if job == '언론인' : par = 'Journalist'\n",
    "    if job == '법조인' : par = 'Law'\n",
    "    if job == '군인' : par = 'Army'\n",
    "    if job == '의료인' : par = 'Medical'\n",
    "    if job == '운동예술' : par = 'Sports/Art'\n",
    "    if job == '전문직' : par = 'Accounting'\n",
    "    if job == '자영업자' : par = 'Self-ownership'\n",
    "    if job == '농업인' : par = 'Agricultural'\n",
    "    if job == '이익단체' : par = 'Interest group'\n",
    "\n",
    "    return par\n",
    "\n",
    "    \n",
    "df['Job'] = df['Job'].apply(lambda x:get_job(x)) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 1440x1440 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(20, 20))\n",
    "\n",
    "\n",
    "G = nx.Graph()\n",
    "\n",
    "# add nodes with labels from the 'Label' column\n",
    "G.add_nodes_from(df['Label'])\n",
    "\n",
    "# add edges based on the connections between the nodes\n",
    "for i in range(len(df)):\n",
    "    for j in range(i+1, len(df)):\n",
    "        if df.loc[i, 'Undergraduate_school'] == df.loc[j, 'Undergraduate_school'] or \\\n",
    "        df.loc[i, 'Job'] == df.loc[j, 'Job'] or df.loc[i, 'K_means'] == df.loc[j, 'K_means']:\n",
    "            G.add_edge(df.loc[i, 'Label'], df.loc[j, 'Label'])\n",
    "\n",
    "# write the edgelist to a CSV file\n",
    "nx.write_edgelist(G, 'model_3.csv', delimiter=',')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# create an empty graph\n",
    "G = nx.Graph()\n",
    "\n",
    "# add nodes with labels from the 'Label' column\n",
    "G.add_nodes_from(df['Label'])\n",
    "\n",
    "# add edges based on the connections between the nodes\n",
    "for i in range(len(df)):\n",
    "    for j in range(i+1, len(df)):\n",
    "        if df.loc[i, 'Undergraduate_school'] == df.loc[j, 'Undergraduate_school'] or \\\n",
    "        df.loc[i, 'Job'] == df.loc[j, 'Job'] or df.loc[i, 'Home'] == df.loc[j, 'Home'] or \\\n",
    "        df.loc[i, 'K_means'] == df.loc[j, 'K_means']:\n",
    "            G.add_edge(df.loc[i, 'Label'], df.loc[j, 'Label'])\n",
    "\n",
    "# write the edgelist to a CSV file\n",
    "nx.write_edgelist(G, 'model_2.csv', delimiter=',')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# create an empty graph\n",
    "G = nx.Graph()\n",
    "\n",
    "# add nodes with labels from the 'Label' column\n",
    "G.add_nodes_from(df['Label'])\n",
    "\n",
    "# add edges based on the connections between the nodes\n",
    "for i in range(len(df)):\n",
    "    for j in range(i+1, len(df)):\n",
    "        if df.loc[i, 'Party'] == df.loc[j, 'Party']:\n",
    "            G.add_edge(df.loc[i, 'Label'], df.loc[j, 'Label'])\n",
    "\n",
    "# write the edgelist to a CSV file\n",
    "nx.write_edgelist(G, 'model_1.csv', delimiter=',')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
